package com.kanqiubao.kq.adapter.main;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.jay.widget.StickyHeaders;
import com.kanqiubao.kq.R;
import com.kanqiubao.kq.ThisAppApplication;
import com.kanqiubao.kq.adapter.BaseAdapter;
import com.kanqiubao.kq.bean.main.MainOneListBean;

import org.jetbrains.annotations.NotNull;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;

/**
 * 首页分组列表
 */
public class MainOneListAdapter extends BaseMultiItemQuickAdapter<MainOneListBean, BaseViewHolder> implements StickyHeaders, StickyHeaders.ViewSetup {
    public MainOneListAdapter() {
        addItemType(MainOneListBean.ITEM, R.layout.item_main_list_layout);
        addItemType(MainOneListBean.GROUP, R.layout.main_list_item_group_layout);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, MainOneListBean o) {
        if (baseViewHolder.getItemViewType() == MainOneListBean.GROUP) {

        } else {
            int pos = baseViewHolder.getLayoutPosition();
            if (pos < 4) {
                baseViewHolder.getView(R.id.sc_root_id)
                        .setBackgroundResource(R.drawable.main_sc_list_item_pm_bg);
            } else {
                baseViewHolder.getView(R.id.sc_root_id).setBackgroundColor(ThisAppApplication.getInstance().getResources().getColor(R.color.white));
            }
        }
    }


    @Override
    public boolean isStickyHeader(int position) {
        return getItemViewType(position) == MainOneListBean.GROUP;
    }

    @Override
    public void setupStickyHeaderView(View view) {
        ViewCompat.setElevation(view, 10);
    }

    @Override
    public void teardownStickyHeaderView(View view) {
        ViewCompat.setElevation(view, 0);
    }

    @Override
    public void onViewAttachedToWindow(BaseViewHolder holder) {
        super.onViewAttachedToWindow(holder);
//        ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
//        if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
//            if (isStickyHeader(holder.getLayoutPosition())) {
//                StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
//                p.setFullSpan(true);
//            }
//        }
    }
}